package br.com.paiva.container.controller;

import java.util.List;

import javax.faces.event.ActionEvent;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import br.com.paiva.container.Moeda;
import br.com.paiva.container.service.MoedaService;
import br.com.paiva.container.util.ImportUtilits;

@Controller
public class MoedaController {	
	
	@Autowired
	@Qualifier("moedaService")
	private MoedaService moedaService;
	
	private Moeda moeda = new Moeda();
	
	public Moeda getMoeda() {
		return moeda;
	}

	public void setMoeda(Moeda moeda) {
		this.moeda = moeda;
	}

	public void setMoedaService(MoedaService moedaService) {
		this.moedaService = moedaService;
	}

	public String save(){
		
		this.moedaService.save(this.moeda);
		this.moeda=null;
		this.moeda = new Moeda();
		return "success";
		
	}
	
	public List<Moeda> getAeroportos(){
		return this.moedaService.list();
	}
	
	public void retrive(ActionEvent event){
		Long id = ImportUtilits.getIdLink(event);
		this.moeda = this.moedaService.getMoedaById(id);
	}
		
	public String delete(ActionEvent event){
		Long id = ImportUtilits.getIdLink(event);
		this.moeda = this.moedaService.getMoedaById(id);
		return "sucess";
	}
		
	public String back(){
		this.moeda = null;
		this.moeda = new Moeda();
		return "back";
	}
	
	public String search(){
		
		this.moedaService.save(this.moeda);
		this.moeda=null;
		this.moeda = new Moeda();
		return "success";
		
	}
	
	public List<String> searchMoedas(Object event){
		return moedaService.searchMoeda(event.toString());
	}
	
}
